
package java6681.newdate;

import javafx.application.Application;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;

import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

/*
 *  分析思路： 母亲节:每月的第二个星期 星期天
 *  封装日期 -> 单独获取年份 -> 按需求修改年份 -> 按照规则更改日期 -> 输出
 * */
public class MothersDay6681Controller {

    @FXML
    private Spinner<Integer> sYear;

    @FXML
    private Label lblMothersDay;

    @FXML
    void buttonClick() {
        /*得到当年5月任何一天的LocalDate对象*/
        LocalDate localDate = LocalDate.of(sYear.getValue(), Month.MAY, 1);
        /*通过API在TemporalAdjusters工具类中找到合适的计算方法*/
        TemporalAdjuster adjuster = TemporalAdjusters.dayOfWeekInMonth(2, DayOfWeek.SUNDAY);
        /*用LocalDate的with()方法计算母亲节*/
        localDate = localDate.with(adjuster);
        /*按格式输出日期*/
        String format = localDate.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL));
//        System.out.println(format);
        lblMothersDay.setText(format);
    }
}
